package com.ecp.base.service;

import org.springframework.stereotype.Repository;

import com.ecp.commons.db.GenericServiceImpl;
import com.ecp.crm.bean.Admin;
import com.ecp.util.MD5;

@Repository("adminService")
public class AdminServiceImpl extends GenericServiceImpl<Admin> implements AdminService {

	@Override
	public Admin adminLogin(String loginId, String password) throws Exception {
		String sql = "SELECT * FROM admin WHERE loginId=?";
		Admin admin = this.getEntity(sql, new Object[] { loginId });
		if (admin == null) {
			throw new Exception("admin not exist");
		}
		if (!admin.getPassword().equals(MD5.getMD5Str(password))) {
			throw new Exception("Password wrong.");
		}
		return admin;
	}
	@Override
	public Admin getAdminById(int adminId) throws Exception {
		return this.load(adminId);
	}

	@Override
	public Admin getAdminByLoginId(String loginId) throws Exception {
		String sql = "select * from admin where loginId= ? ";
		return this.getEntity(sql, new Object[] { loginId });
	}

}
